Commentary - Sample Code (RedirectCommentary)

Commentary - Sample Code (RedirectCommentary)

The Commentary plugin in this example does the following:

 

The sample code will cover the following:

Setup

This sample code needs the following to run:

About the RedirectCommentary plugin

To setup this scenario:

  1. Copy the rulebase .zip file (Parents and Children.zip) from examples\rulebases\compiled to the rulebase folder in Web Determinations (for example, <webroot>\WEB-INF\classes\rulebases)
  2. Copy and install the RedirectCommentary.jar file or the RedirectCommentary.dll file(located in examples\interview-engine\redirect-commentary in either the Java or .NET runtime zip) into Web Determinations; for more information, refer to Create a Plugin.

    If you wish to modify the RedirectCommentary code, do the following:
    1. Copy the code for the RedirectCommentary plugin
    2. Modify the static map (variable redirectMap) used for the targets and URL mappings in the code if necessary
    3. Modify the getInstance(arguments) method for registration of the plugin with the rulebase if necessary
    4. Compile and JAR (or build the DLL in .NET) the RedirectCommentary

  3. Run a Web Determinations Interview

How the RedirectCommentary plugin works

Once registered, Web Determinations will call the RedirectCommentary.isCommentaryEnabled() when a screen is to be displayed; the RedirectCommentary plugin always returns true.

When a screen is to be displayed, Web Determinations calls RedirectCommentary.hasCommentary() method for the screen itself, to check if commentary information exists for the screen. The same method is also called for each attribute control to be displayed in the screen. RedirectCommentary.hasCommentary() uses the target information and the locale information from InterviewSession to verify if a URL exists for the target in the mapping object

If RedirectCommentary.hasCommentary() returns true for a target, its label is rendered as a link.

When the user clicks on the label link, Web Determinations calls RedirectCommentary.isCommentaryRedirect() to check if the commentary for the target (the clicked label link) returns URL or HTML content; the RedirectCommentary plugin always returns true.

Web Determinations then calls RedirectCommentary.getCommentaryContent() to get the URL for the target. RedirectCommentary simply retrieves the value from the mapping object using the target String and the locale from the InterviewSession as the key. RedirectCommentary returns the URL value as is, and Web Determinations displays the webpage of the URL as commentary.

A similar sequence of the above can be seen in Commentary Plugin

Source Code

To view the source code for the RedirectCommentary sample, refer to examples/interview-engine/redirect-commentary in either the Java or .NET runtime zip file.